package tongcheng.com.tongcheng.base.xinyong;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import tongcheng.com.tongcheng.ConStans;
import tongcheng.com.tongcheng.R;
import tongcheng.com.tongcheng.adapter.XinYuJiFenAdapter;
import tongcheng.com.tongcheng.base.BaseActivity;
import tongcheng.com.tongcheng.bean.XinYuJiFenBean;
import tongcheng.com.tongcheng.network.CallServer;
import tongcheng.com.tongcheng.network.MyRequest;
import tongcheng.com.tongcheng.network.OnCallBack;
import tongcheng.com.tongcheng.utils.GsonUtil;
import tongcheng.com.tongcheng.utils.Setting;
import tongcheng.com.tongcheng.utils.ShowToast;

public class XinYongFenActivity extends BaseActivity {

    @Bind(R.id.back)
    ImageView mBack;
    @Bind(R.id.back_text)
    TextView mBackText;
    @Bind(R.id.title)
    TextView mTitle;
    @Bind(R.id.title_bar)
    RelativeLayout mBg;
    @Bind(R.id.xinyong_fenshu)
    Button mXinyongFenshu;
    @Bind(R.id.xinyong_guize)
    TextView mXinyongGuize;
    @Bind(R.id.xinyong_jilu)
    TextView mXinyongJilu;

    @Bind(R.id.xinyong_rc)
    RecyclerView mXinyongRc;

    public List<XinYuJiFenBean.DataBean> datas = new ArrayList<>();
    private XinYuJiFenAdapter mXinYuJiFenAdapter;

    @Override
    public Integer initResid() {

        return R.layout.activity_xin_yong_fen;
    }

    @Override
    public void initCreate(Bundle savedInstanceState) {
        settitlebar(mBg);
        mTitle.setText("信誉积分");
        mBg.setBackgroundColor(Color.TRANSPARENT);
        mBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });

        mXinyongFenshu.setText(Setting.getXinYongFen() + "");

        mXinyongGuize.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startactivity(XinYongFenActivity.this, GuiZeActivity.class);
            }
        });

        mXinyongJilu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startactivity(XinYongFenActivity.this, XinYongLishiActivity.class);
            }
        });
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);

        mXinyongRc.setLayoutManager(linearLayoutManager);
        mXinYuJiFenAdapter = new XinYuJiFenAdapter(this,datas);
        mXinyongRc.setAdapter(mXinYuJiFenAdapter);


        initData();

    }

    private void initData() {
        MyRequest request = new MyRequest(ConStans.XinYongFen_Url);
        request.add("type", 2);
        request.add("userid", Setting.getId());
        CallServer.getInstance().addPost(this,request, 1, new OnCallBack() {
            @Override
            public void OnSuccess(int what, String json, Object ject) {
                Log.e("信用分",json + "");
                XinYuJiFenBean xinYuJiFenBean = GsonUtil.GsonToBean(json, XinYuJiFenBean.class);
                if (xinYuJiFenBean != null) {

                    ShowToast.showToast(xinYuJiFenBean.msg);

                    if (xinYuJiFenBean.data != null) {
                        List<XinYuJiFenBean.DataBean> data = xinYuJiFenBean.data;
                        datas.clear();
                        datas.addAll(data);
                        mXinYuJiFenAdapter.notifyDataSetChanged();
                    }
                }
            }
        });
    }

}
